<template>
  <div>
    <div class="zt1">
      <img :src="headImg" class="ztimg"/> 
    </div>

    <div class="inputInfo">

      <textarea class="inpcls" :placeholder="tip1" v-model.trim="realName"/>
      <textarea class="inpcls" :placeholder="tip2" v-model.trim="userCode"/>

      <!-- <div class="tipspan1">
        {{protect}}
      </div> -->

      <!-- <div class="tipspan">
        {{warntip}}
      </div> -->
    
      <div class="divcls">
        <a class="butclass2" @click="checkName()">开始核查</a>
      </div>

      <div class="rel">
        <div class="flushbut">
          <img class="rrs1" src="/static/images/sxx.png" @click="getRecords('1')"/>
        
        </div>
        <div class="findRecord"  v-for="(record, index) in records"  :key="index">
          <div class="recordImage">
            <img :src="record.realHead" class="imgbg"  @click="gopage('/pages/good/main?fromUserId='+record.fromUserId+'&recordId='+record.recordId)"/>
          </div>
          <div class="recordName">{{ record.realName }}</div>
          <div class="recordInfo"  @click="gopage('/pages/good/main?fromUserId='+record.fromUserId+'&recordId='+record.recordId)">
            <div class="recordinfo2">查看</div>
          </div>
        </div>

        <div class="findRecord">
          <div class="recordImage">
            <img :src="shopImg" class="imgbg" @click="gopage('/pages/good/main?fromUserId=-1&id=-1')"/>
          </div>
          <div class="recordName">{{shopName}}</div>
          <div class="recordInfo" @click="gopage('/pages/good/main?fromUserId=-1&id=-1')">查看</div>
        </div>
      </div>
      
      <div :style="{ width:'93%',position:'relative',height:'180rpx',top:'20px',margin:'0 auto'}">
        <div  :style="{ position:'absolute',bottom:'0',width: '100%', height: '180rpx', fontSize: '50rpx'}">
          <official-account></official-account>
        </div>
      </div>

      
      <div :style="{width:'100%', float:'left',height:'35px'}"></div>

    </div>


  </div>
  
</template>

<script>
import card from '@/components/card'
import { requestPost, getOpenId } from '@/utils/index'

export default {
  components: {
    card
  },
  data () {
    return {
      tip1: '名称',
      tip2: '来源',
      warntip: '',
      headImg: '',
      shopImg: '/static/images/tp0.png',
      shopName: '名称',
      records: [],
      limit: 5,
      pageSize: 1,
      realName: '',
      userCode: '',
      protect: '我同意遵守《用户个人信息保护》协议',
      pid: 0
    }
  },
  async onLoad (option) {
    await mpvue.setStorageSync('co', false)
    if (option.q) {
      let pp = decodeURIComponent(option.q)
      this.pid = pp.split('=')[1]
    }
    await mpvue.setStorageSync('pid', this.pid)
    await getOpenId()
    await console.log('s2--token:' + mpvue.getStorageSync('token'))
    await this.loadData()
  },
  async onShow () {},
  onReachBottom () {
    if (!mpvue.getStorageSync('co')) {
      return
    }
    this.pageSize = this.pageSize + 1
    this.getRecords('0')
  },
  onUnload () {
    this.pageSize = 1
    this.records = []
    mpvue.removeStorageSync('token')
  },
  created () {
    // console.log('created---')
  },
  methods: {
    showMyToast (title, duration, mask) {
      wx.showToast({
        title: title,
        icon: 'none',
        duration: duration,
        mask: mask
      })
    },
    loadData () {
      var that = this
      var data = {}
      requestPost(mpvue.getStorageSync('requestUrl') + '/miniprogram/loadData', data, 'POST').then(function (value) {
        if (value.data === '1') {
          mpvue.setStorageSync('co', true)
          that.headImg = 'http://106.55.147.43/jcimg/ztg.gif'
          that.tip1 = '姓名'
          that.tip2 = '授权码'
          that.shopImg = 'http://106.55.147.43/jcimg/slt2.png'
          that.shopName = '王初易'
          that.protect = '我同意遵守《用户个人信息保护》协议'
        } else {
          that.showMyToast('系统升级维护,抱歉给您带来不便,详情咨询客服QQ:2602685638', 9999999, false)
        }
      }, function (value) {
        that.showMyToast(value.message, 2000, false)
      })
    },
    gopage (pathstr) {
      wx.navigateTo({
        url: pathstr
      })
    },
    getRecords (isflush) {
      if (!mpvue.getStorageSync('co')) {
        return
      }
      if (!mpvue.getStorageSync('userId')) {
        return
      }
      if (isflush === '1') {
        this.pageSize = 1
      }
      var data = {
        'userId': mpvue.getStorageSync('userId'),
        'page': this.pageSize,
        'limit': this.limit,
        'token': mpvue.getStorageSync('token')
      }
      var that = this
      requestPost(mpvue.getStorageSync('requestUrl') + '/miniprogram/getRecords', data, 'POST').then(function (value) {
        if (value.code === 0) {
          if (value.data.length === 0) {
            that.showMyToast('暂无核查记录', 2000, false)
            return
          }
          if (isflush === '1') {
            that.records = []
          }
          for (var ele of value.data) {
            if (ele.realHead == null) {
              ele.realHead = '/static/images/rytx.png'
            }
            that.records.push(ele)
          }
        } else {
          that.showMyToast(value.message, 2000, false)
        }
      }, function (value) {
        that.showMyToast(value.message, 2000, false)
      })
    },
    checkName () {
      if (!mpvue.getStorageSync('co')) {
        this.gopage('/pages/good/main?fromUserId=-1&id=-1')
        return
      }
      if (this.realName === '') {
        this.showMyToast('姓名不能为空', 2000, false)
        return
      }
      if (this.userCode === '') {
        this.showMyToast('授权码不能为空', 2000, false)
        return
      }
      wx.showLoading({
        title: '',
        mask: true
      })
      var data = {
        'realName': this.realName.replace(/[ ]|[\r\n]/g, ''),
        'code': this.userCode.replace(/[ ]|[\r\n]/g, ''),
        'uid': mpvue.getStorageSync('userId'),
        'token': mpvue.getStorageSync('token')
      }
      var that = this
      requestPost(mpvue.getStorageSync('requestUrl') + '/miniprogram/checkName', data, 'POST').then(function (value) {
        if (value.code === 200032) {
          wx.hideLoading()
          wx.showModal({
            title: '未人脸核身',
            content: '是否开始人脸核身',
            success (res) {
              if (res.confirm) {
                console.log('用户点击确定')
                that.gopage('/pages/addr/main')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
          return
        }
        if (value.code === 200038) {
          wx.hideLoading()
          wx.showModal({
            title: value.message,
            content: '无限次核查,是否开通',
            success (res) {
              if (res.confirm) {
                console.log('用户点击确定')
                var data = {
                  'type': '1',
                  'userId': mpvue.getStorageSync('userId'),
                  'token': mpvue.getStorageSync('token')
                }
                requestPost(mpvue.getStorageSync('requestUrl') + '/wxPay/unifiedOrder', data, 'POST').then(function (value) {
                  // console.log(value)
                  if (value.code === 0) {
                    wx.requestPayment({
                      timeStamp: value.data.timeStamp,
                      nonceStr: value.data.nonceStr,
                      package: value.data.package,
                      signType: value.data.signType,
                      paySign: value.data.paySign,
                      success (res) {
                        that.showMyToast('支付成功', 2000, false)
                      },
                      fail (res) {
                        that.showMyToast('支付失败', 2000, false)
                      }
                    })
                  }
                }, function (value) {
                  that.showMyToast(value.message, 2000, false)
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
          return
        }
        if (value.code === 200039) {
          wx.hideLoading()
          wx.showModal({
            title: value.message,
            content: '无限次核查,是否续费',
            success (res) {
              if (res.confirm) {
                console.log('用户点击确定')
                var data = {
                  'type': '2',
                  'userId': mpvue.getStorageSync('userId'),
                  'token': mpvue.getStorageSync('token')
                }
                requestPost(mpvue.getStorageSync('requestUrl') + '/wxPay/unifiedOrder', data, 'POST').then(function (value) {
                  if (value.code === 0) {
                    wx.requestPayment({
                      timeStamp: value.data.timeStamp,
                      nonceStr: value.data.nonceStr,
                      package: value.data.package,
                      signType: value.data.signType,
                      paySign: value.data.paySign,
                      success (res) {
                        that.showMyToast('支付成功', 2000, false)
                      },
                      fail (res) {
                        that.showMyToast('支付失败', 2000, false)
                      }
                    })
                  }
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
          return
        }
        if (value.code === 0) {
          wx.hideLoading()
          that.gopage('/pages/good/main?fromUserId=' + value.data.userId + '&recordId=' + value.data.recordId)
        } else {
          wx.hideLoading()
          that.showMyToast(value.message, 2000, true)
        }
      }, function (value) {
        wx.hideLoading()
        that.showMyToast(value.message, 2000, false)
      })
    }
  }
}
</script>

<style scoped>
.flushbut{
  width: 90%;
  height: 35px;
  margin: 10px auto;
}
.rrs1{
  width: 30px;
  height: 30px;
  float: left;
  line-height: 35px;
  margin-top:0px;
}
.zt1{
  width: 100%;
  height: 110px;
  float:left;
}
.ztimg{
  width: 100%;
  height: 110px;
}
.rel{
  margin-top: 0px;
  width: 100%;
  clear: both;
}
.bg{
  padding-top:10px;
}
.noticeimg{
  width: 100%;
  height: 80px;
}
.noticebg{
  width: 90%;
  height: 80px;
  margin: 0px auto;
  padding-top: 5px;
}
.inputInfo{
  width: 100%;
  height: 150px;
  float:left;
}
.tipspan{
  margin: 20px auto;
  width: 90%;
  font-size: 15px;
  color: #ccc;
}
.tipspan1{
  margin: 20px auto;
  width: 90%;
  font-size: 15px;
  /* color: rgb(133, 176, 255); */
  color: rgb(146, 146, 146);
}
.divcls{
  width: 90%;
  height: 50px;
  margin-left:20px;
  background-color: #FEF55A;
}
.butclass2{
  line-height: 50px;
  font-size: 25px;
  text-align: center;
  color: rgb(14, 14, 22);
}
.inpcls{
  border-bottom: 1px solid #FEF55A;
  margin: 20px auto;
  width: 90%;
  height: 50px;
  line-height: 50px;
  font-size: 24px;
}
.goodbg1{
  width: 90%;
  height: 250px;
  border-radius: 3%;
  margin: 0px auto;
}
.goodbg11{
  width: 100%;
  height: 220px;
  border-radius: 3%;
  margin: 0px auto;
  margin-bottom: 30px;
  background-size:contain;
  position: relative;
  z-index: 1;
}
.dwwz{
  width: 100%;
  height: 60px;
  position: relative;
  z-index: 2;
  margin-top: -177rpx;
  border-radius: 0px 0px 8px 8px;
  background-color: rgba(253, 253, 253, 0.767);
}

.goodbg4{
  width: 100%;
  height: 60px;
  margin-top: -60px;
  position: relative;
  z-index: 4;
}
.goodbg2{
  width: 92%;
  height: 144.928rpx;
  border-radius: 3%;
  margin-top: -110rpx;
  position: relative;
  z-index: 4;
}
.goodbg3{
  width: 100%;
  height: 130px;
  border-radius: 0%;
  margin: 0 auto;
  float: left;
}
.gbgword{
  width: 60%;
  height: 60px;
  float: left;
  margin-left:5px;
}
.gbgimg{
  width: 30%;
  height: 60px;
  float: right;
  background-color: rgba(255, 251, 0, 0.699);
  border-radius: 0px 0px 8px 0px;
}
.wordtop{
  width: 100%;
  height: 30px;
}
.wordbottom{
  width: 100%;
  height: 30px;
  font-size: 15px;
  line-height: 30px;
  overflow: hidden;
  text-overflow:ellipsis;
  white-space: nowrap;
}
.wordleft{
  width: 70%;
  height: 30px;
  float: left;
  font-size: 18px;
  line-height: 30px;
  font-weight:bold;
  color: rgb(87, 19, 19);
  overflow: hidden;
  text-overflow:ellipsis;
  white-space: nowrap;
}
.wordright{
  width: 30%;
  height: 30px;
  float: left;
  font-size: 18px;
  text-decoration: line-through;
  line-height: 30px;
}
.imgbg{
  width: 100%;
  height: 100px;
  border-radius: 10px 10px 10px 10px;
}
.recordImage{
  width: 40%;
  height: 100px;
  float: left;
  margin-bottom: 10px;
}
.recordName{
  width: 30%;
  height: 100px;
  float: left;
  line-height: 100px;
  padding-left: 20px;
  margin-bottom: 10px;
}
.recordInfo{
  width: 20%;
  height: 100px;
  float: right;
  line-height: 100px;
  margin-bottom: 10px;
    color: rgb(255, 122, 195);
  font-weight: bold;
}
.recordInfo2{
  border: 1px solid rgb(0, 0, 255);
}
.findRecord{
  width: 90%;
  margin: 0 auto;
  height: 100px;
}
.qgimg{
  width: 100%;
  height: 120px;
}
.rtb{
  width: 100%;
  height: 60px;
  font-size: 28px;
  font-weight: bold;
  text-align: center;
  line-height: 60px;
}
.rtb2{
  width: 100%;
  font-size: 15px;
  text-align: center;
}

</style>
